home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS03.ADF
/
C
/
cleanup.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-04-02
|
1KB
|
58 lines
/* CLEANUP.C - (c) 1985 John Hodgson */
/* ================================= */
/* Use CLEANUP regularly to filter illegal chars for ED */
/* while converting CR's to LF's and removing redundant */
/* CR's in CR/LF pairs for legibility. */
#include <lattice/stdio.h>
#define LF 10
#define CR 13
main(argc,argv)
int argc;
char *argv[];
{
FILE *rdptr,*wrtptr;
int c,predc,srclen,dstlen,filter,cr;
printf("\nCLEANUP.C Text file cleanup utility (c) 1985 John Hodgson\n\n");
if (argc!=3) {
printf("Usage : cleanup srcfile destfile\n");
exit(0);
}
if ((rdptr=(FILE *)fopen(argv[1],"r"))==NULL) {
printf("Error opening file %s for reading.\n",argv[1]);
exit(0);
}
if ((wrtptr=(FILE *)fopen(argv[2],"w"))==NULL) {
printf("Error opening file %s for writing.\n",argv[2]);
exit(0);
}
srclen=dstlen=cr=filter=predc=NULL;
while ((c=getc(rdptr))!=EOF) {
srclen++;
if ((c!=LF && c!=CR) && (c<' ' || c>127)) {
c=NULL;
filter++;
}
if (c==LF && predc==CR) {
c=NULL;
cr++;
}
else predc=c;
if (c==CR) c=LF;
if (c!=NULL) { putc(c,wrtptr); dstlen++; }
}
fclose(rdptr); fclose(wrtptr);
printf("Source file len = %d, Result file len = %d\n",srclen,dstlen);
printf("Chars filtered = %d, CR's removed = %d\n\n",filter,cr);
}